
;; ░▒█▀▀▀█░░▀░░▀█▀░█▀▀▄░█░▒█░█░█▀▀░░░▒█▀▀▀░█▀▄▀█░█▀▀▄░█▀▄░█▀▀░░░▀█▀░▒█▀▀▄░▒█▀▀▀░░░▒█▀▀▄░░░░░░░░
;; ░░▀▀▀▄▄░░█▀░░█░░█▄▄▀░█░▒█░░░▀▀▄░░░▒█▀▀▀░█░▀░█░█▄▄█░█░░░▀▀▄░░░▒█░░▒█░▒█░▒█▀▀▀░░░▒█░░░░▄█▄░▄█▄
;; ░▒█▄▄▄█░▀▀▀░░▀░░▀░▀▀░░▀▀▀░░░▀▀▀░░░▒█▄▄▄░▀░░▒▀░▀░░▀░▀▀▀░▀▀▀░░░▄█▄░▒█▄▄█░▒█▄▄▄░░░▒█▄▄▀░░▀░░░▀░


;;░▒█▀▀▀░█░▒█░█▀▀▄░█▀▄░▀█▀░░▀░░▄▀▀▄░█▀▀▄░█▀▀
;;░▒█▀▀░░█░▒█░█░▒█░█░░░░█░░░█▀░█░░█░█░▒█░▀▀▄
;;░▒█░░░░░▀▀▀░▀░░▀░▀▀▀░░▀░░▀▀▀░░▀▀░░▀░░▀░▀▀▀

;; Start Emacs as a server
(require 'server)
(unless (server-running-p)
	(server-start))

(defun save-buffer-always ()
  "Save the buffer even if it is not modified."
  (interactive)
  (set-buffer-modified-p t)
  (save-buffer))
 
;;░▒█░░▒█░█▀▀▄░█▀▀▄░░▀░░█▀▀▄░█▀▀▄░█░░█▀▀░█▀▀
;;░░▒█▒█░░█▄▄█░█▄▄▀░░█▀░█▄▄█░█▀▀▄░█░░█▀▀░▀▀▄
;;░░░▀▄▀░░▀░░▀░▀░▀▀░▀▀▀░▀░░▀░▀▀▀▀░▀▀░▀▀▀░▀▀▀

;; Disable GUI components
(tooltip-mode      -1)
(menu-bar-mode     -1) ;; отключаем графическое меню
(tool-bar-mode     -1) ;; отключаем tool-bar
(scroll-bar-mode   -1) ;; отключаем полосу прокрутки
(blink-cursor-mode -1) ;; курсор не мигает

(setq x-select-enable-clipboard nil)

(defun paste-from-clipboard ()
  (interactive)
  (setq x-select-enable-clipboard t)
  (yank)
  (setq x-select-enable-clipboard nil))

(defun copy-to-clipboard()
  (interactive)
  (setq x-select-enable-clipboard t)
  (kill-ring-save (region-beginning) (region-end))
  (setq x-select-enable-clipboard nil))

(setq use-dialog-box     nil)     ;; никаких графических диалогов и окон все через минибуфер
(setq redisplay-dont-pause t)     ;; лучшая отрисовка буфера
(setq ring-bell-function 'ignore) ;; отключить звуковой сигнал

(setq frame-title-format "Emacs IDE C++")
(setq inhibit-splash-screen   t)
(setq inhibit-startup-message t  ; Don't show the splash screen
      visible-bell t)            ; Flash when the bell rings
(setq auto-window-vscroll nil)
(setq fast-but-imprecise-scrolling nil)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)))
(setq mouse-wheel-progressive-speed nil)

(global-display-line-numbers-mode 1) ; Line numbers
(setq x-select-enable-clipboard t) ;; Clipboard settings

;; Tabs to spaces
;;(setq-default indent-tabs-mode nil) ;; отключить возможность ставить отступы TAB'ом
;;(setq-default tab-width          4) ;; ширина табуляции - 4 пробельных символа
;;(setq-default c-basic-offset     4)
;;(setq-default standart-indent    4) ;; стандартная ширина отступа - 4 пробельных символа
;;(global-set-key (kbd "RET") 'newline-and-indent) ;; при нажатии Enter перевести каретку и сделать отступ
;;(setq lisp-indent-function  'common-lisp-indent-function)

;; End of file newlines
(setq require-final-newline    t) ;; добавить новую пустую строку в конец файла при сохранении
(setq next-line-add-newlines nil) ;; не добавлять новую строку в конец при смещении курсора стрелками

;; Highlight search resaults
(setq search-highlight        t)
(setq query-replace-highlight t)

;; Endcoding
(setq default-buffer-file-coding-system 'utf-8)
(setq-default coding-system-for-read    'utf-8)
(setq file-name-coding-system           'utf-8)
(set-selection-coding-system            'utf-8)
(set-keyboard-coding-system        'utf-8-unix)
(set-terminal-coding-system             'utf-8)
(prefer-coding-system                   'utf-8)

;; Short messages
(defalias 'yes-or-no-p 'y-or-n-p)
(evil-mode 1)



;;░▒█░▄▀░█▀▀░█░░█░▒█▀▄▀█░█▀▀▄░▄▀▀▄░█▀▀
;;░▒█▀▄░░█▀▀░█▄▄█░▒█▒█▒█░█▄▄█░█▄▄█░▀▀▄
;;░▒█░▒█░▀▀▀░▄▄▄▀░▒█░░▒█░▀░░▀░█░░░░▀▀▀


(with-eval-after-load 'evil-maps
  (define-key evil-normal-state-map (kbd "C-n") nil)
  (define-key evil-normal-state-map (kbd "C-p") nil))

;;░▒█▀▀█░█░░█░▒█░█▀▀▀░░▀░░█▀▀▄░█▀▀
;;░▒█▄▄█░█░░█░▒█░█░▀▄░░█▀░█░▒█░▀▀▄
;;░▒█░░░░▀▀░░▀▀▀░▀▀▀▀░▀▀▀░▀░░▀░▀▀▀

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

(use-package evil
  :ensure t
  :init)
 
  

;; Icons
(use-package all-the-icons
  :ensure t
  :if (display-graphic-p))

;; Smooth scroll
(use-package good-scroll
   :ensure t
   :init
   (global-set-key [next] #'good-scroll-up-full-screen)
   (global-set-key [prior] #'good-scroll-down-full-screen)
   :config
   (good-scroll-mode 1))

;; Cursor hightlight
(use-package beacon
   :ensure t
   :config 
   (beacon-mode 1))

;; File explorer
(use-package treemacs
  :ensure t
  :defer t
  :init
  (with-eval-after-load 'winum
    (define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
  :config
  (progn
    (setq treemacs-collapse-dirs                   (if treemacs-python-executable 3 0)
          treemacs-deferred-git-apply-delay        0.5
          treemacs-directory-name-transformer      #'identity
          treemacs-display-in-side-window          t
          treemacs-eldoc-display                   'simple
          treemacs-file-event-delay                2000
          treemacs-file-extension-regex            treemacs-last-period-regex-value
          treemacs-file-follow-delay               0.2
          treemacs-file-name-transformer           #'identity
          treemacs-follow-after-init               t
          treemacs-expand-after-init               t
          treemacs-find-workspace-method           'find-for-file-or-pick-first
          treemacs-git-command-pipe                ""
          treemacs-goto-tag-strategy               'refetch-index
          treemacs-header-scroll-indicators        '(nil . "^^^^^^")
          treemacs-hide-dot-git-directory          t
          treemacs-indentation                     2
          treemacs-indentation-string              " "
          treemacs-is-never-other-window           nil
          treemacs-max-git-entries                 5000
          treemacs-missing-project-action          'ask
          treemacs-move-forward-on-expand          nil
          treemacs-no-png-images                   nil
          treemacs-no-delete-other-windows         t
          treemacs-project-follow-cleanup          nil
          treemacs-persist-file                    (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
          treemacs-position                        'left
          treemacs-read-string-input               'from-child-frame
          treemacs-recenter-distance               0.1
          treemacs-recenter-after-file-follow      nil
          treemacs-recenter-after-tag-follow       nil
          treemacs-recenter-after-project-jump     'always
          treemacs-recenter-after-project-expand   'on-distance
          treemacs-project-follow-into-home        nil
          treemacs-show-cursor                     nil
          treemacs-show-hidden-files               t
          treemacs-silent-filewatch                nil
          treemacs-silent-refresh                  nil
          treemacs-sorting                         'alphabetic-asc
          treemacs-select-when-already-in-treemacs 'move-back
          treemacs-space-between-root-nodes        t
          treemacs-tag-follow-cleanup              t
          treemacs-tag-follow-delay                1.5
          treemacs-text-scale                      nil
          treemacs-user-mode-line-format           nil
          treemacs-user-header-line-format         nil
          treemacs-wide-toggle-width               70
          treemacs-width                           35
          treemacs-width-increment                 1
          treemacs-width-is-initially-locked       t
          treemacs-workspace-switch-cleanup        nil)
    (treemacs-follow-mode t)
    (treemacs-filewatch-mode t)
    (treemacs-fringe-indicator-mode 'always)
    (when treemacs-python-executable
      (treemacs-git-commit-diff-mode t))

    (pcase (cons (not (null (executable-find "git")))
                 (not (null treemacs-python-executable)))
      (`(t . t)
       (treemacs-git-mode 'deferred))
      (`(t . _)
       (treemacs-git-mode 'simple)))

    (treemacs-hide-gitignored-files-mode nil))
  :bind
  (:map global-map
        ("M-0"       . treemacs-select-window)
        ("C-x t 1"   . treemacs-delete-other-windows)
        ("C-x t t"   . treemacs)
        ("C-x t d"   . treemacs-select-directory)
        ("C-x t B"   . treemacs-bookmark)
        ("C-x t C-t" . treemacs-find-file)
        ("C-x t M-t" . treemacs-find-tag)))

(use-package treemacs-projectile
  :after (treemacs projectile)
  :ensure t)

(use-package treemacs-icons-dired
  :hook (dired-mode . treemacs-icons-dired-enable-once)
  :ensure t)

(use-package treemacs-magit
  :after (treemacs magit)
  :ensure t)

(use-package treemacs-persp ;;treemacs-perspective if you use perspective.el vs. persp-mode
  :after (treemacs persp-mode) ;;or perspective vs. persp-mode
  :ensure t
  :config (treemacs-set-scope-type 'Perspectives))

(use-package treemacs-tab-bar ;;treemacs-tab-bar if you use tab-bar-mode
  :after (treemacs)
  :ensure t
  :config (treemacs-set-scope-type 'Tabs))

;; Multiple cursors (edit two and > strings)
(use-package multiple-cursors
  :ensure t
  :init
 ;; (global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
  (global-unset-key (kbd "M-<down-mouse-1>"))
  (global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)
  (global-set-key (kbd "C->") 'mc/mark-next-like-this)
  (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
  (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this))

;; Terminal
(use-package shell-pop
  :ensure t
  :config
  (custom-set-variables
  '(shell-pop-default-directory "~/")
  '(shell-pop-shell-type (quote ("ansi-term" "*ansi-term*" (lambda nil (ansi-term shell-pop-term-shell)))))
  '(shell-pop-term-shell "/bin/bash")
  '(shell-pop-universal-key "M-9")
  '(shell-pop-window-size 30)
  '(shell-pop-full-span t)
  '(shell-pop-window-position "bottom")
  '(shell-pop-autocd-to-working-dir t)
  '(shell-pop-restore-window-configuration t)
  '(shell-pop-cleanup-buffer-at-process-exit t)))


;; lsp mode
(use-package lsp-mode
  :ensure t 
  :hook (
	(c++-mode . lsp)
	(python-mode . lsp)
	(go-mode . lsp)
	(css-mode . lsp)
	(html-mode . lsp)
	(js-mode . lsp)
	(lua-mode . lsp)
	(ssas-mode . lsp)
        (markdown-mode . lsp)
        (markdown-mode . lsp)
	))

;; lsp ui
(use-package lsp-ui
  :ensure t
  :after lsp-mode
  :custom
  (lsp-ui-doc-show-with-cursor t))

;; Auto complite
(use-package company
  :ensure t
  :init (global-company-mode)
  :bind (:map company-active-map
	 ("<tab>" . company-select-next)
	 ("<backtab>" . company-select-previous))
  :custom
  (company-minimum-prefix-length 1)
  (company-idle-delay 0.01))

;; Ui window (check type, arguments, etc to vars, functions)
;; apt install elpa-flycheck flycheck-doc
(use-package flycheck
  :ensure t
  :init (global-flycheck-mode))

;; Parens
(use-package smartparens
  :ensure t)

(use-package smartparens-config
  :ensure smartparens
  :init
  (add-hook 'prog-mode-hook 'turn-on-smartparens-strict-mode)
  :config (progn (show-smartparens-global-mode t)))

;; Move line
(use-package move-text
  :ensure t
  :init
  (move-text-default-bindings))
 

;; Clipboard
(use-package clipetty
  :ensure t
  :hook (after-init . global-clipetty-mode))

;; Debugger
(use-package dap-mode
  :defer
  :custom
  (dap-auto-configure-mode t                           "Automatically configure dap.")
  (dap-auto-configure-features
   '(sessions locals breakpoints expressions tooltip)  "Remove the button panel in the top.")
  :config
  ;;; dap for c++
  (require 'dap-cpptools)

  ;;; set the debugger executable (c++)
  (setq dap-lldb-debug-program '("/usr/bin/gdb"))

  ;;; ask user for executable to debug if not specified explicitly (c++)
  (setq dap-lldb-debugged-program-function (lambda () (read-file-name "Select file to debug.")))

  ;;; default debug template for (c++)
  (dap-register-debug-template
   "C++ gdb dap"
   (list :type "gdb"
         :cwd nil
         :args nil
         :request "launch"
         :program nil))
  
  (defun dap-debug-create-or-edit-json-template ()
    "Edit the C++ debugging configuration or create + edit if none exists yet."
    (interactive)
    (let ((filename (concat (lsp-workspace-root) "/launch.json"))
	  (default "~/.emacs.d/default-launch.json"))
      (unless (file-exists-p filename)
	(copy-file default filename))
      (find-file-existing filename))))

;; Dashboard
(use-package dashboard
  :ensure t
  :init
  (setq dashboard-banner-logo-title nil)
  (setq dashboard-startup-banner "~/.emacs.d/banner.txt")
  (setq dashboard-icon-type 'all-the-icons) 
  (setq dashboard-show-shortcuts t)
  (setq dashboard-center-content t)
  (setq dashboard-set-heading-icons t)
  (setq dashboard-set-file-icons t)
  (setq dashboard-items '((recents  . 4)
                        (projects . 8)
                        (agenda . 4)))
  (setq dashboard-footer-messages '("I want to write a program that ..."))
  (setq dashboard-footer-icon (all-the-icons-alltheicon "cplusplus-line"
                                                   :height 1.4
                                                   :v-adjust -0.05
                                                   :face 'font-lock-keyword-face))
  (setq dashboard-week-agenda t)
  :config
  (dashboard-modify-heading-icons '((projects . "file-text")))
  (dashboard-setup-startup-hook))


;;░▀▀█▀▀░▒█░▒█░▒█▀▀▀░▒█▀▄▀█░▒█▀▀▀
;;░░▒█░░░▒█▀▀█░▒█▀▀▀░▒█▒█▒█░▒█▀▀▀
;;░░▒█░░░▒█░▒█░▒█▄▄▄░▒█░░▒█░▒█▄▄▄


(use-package kaolin-themes
  :ensure t
  :config
  (load-theme 'kaolin-aurora t)
  (kaolin-treemacs-theme))








;;░░░▀░█▀▀▄░█▀▀▄░█▀▀▄░█▀▀░█▀▀▄
;;░░░█░█▄▄█░█▀▀▄░█▀▀▄░█▀▀░█▄▄▀
;;░█▄█░▀░░▀░▀▀▀▀░▀▀▀▀░▀▀▀░▀░▀▀

(setq user-full-name   "UserName")
(setq user-mail-adress "UserMail")

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages
   '(simpleclip use-package treemacs-tab-bar treemacs-projectile treemacs-persp treemacs-magit treemacs-icons-dired sublimity smartparens shell-pop multiple-cursors move-text lsp-ui kaolin-themes good-scroll focus flycheck evil dashboard company beacon all-the-icons))
 '(shell-pop-autocd-to-working-dir t)
 '(shell-pop-cleanup-buffer-at-process-exit t)
 '(shell-pop-default-directory "~/")
 '(shell-pop-full-span t)
 '(shell-pop-restore-window-configuration t)
 '(shell-pop-shell-type
   '("ansi-term" "*ansi-term*"
     (lambda nil
       (ansi-term shell-pop-term-shell))))
 '(shell-pop-term-shell "/bin/bash")
 '(shell-pop-universal-key "C-t")
 '(shell-pop-window-position "bottom")
 '(shell-pop-window-size 30)
 '(warning-suppress-types '((comp))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
